﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HAUtil.DosRunUtil;

using HA.ModFlow.Application;

namespace HA.ModFlow.Application.DosRun
{
   public  class ModFlowSolution:IRunable
    {

       

        #region IRunable 成员

       bool _shouldRun=true;

        public bool ShouldRun
        {
            get
            {
               return  _shouldRun;
            }
            set
            {
               _shouldRun=value;
            }
        }

        string _instanceId="modflow";

        public string RunInstanceId
        {
            get
            {
                return _instanceId;
            }
            set
            {
                _instanceId=value;
            }
        }

        string _instanceName = "modflow";

        public string RunInstanceName
        {
            get
            {
                return _instanceName;
            }
            set
            {
                _instanceName = value;
            }
        }

        bool _runCatchError;
        public bool RunCatchError
        {
            get
            {
                return _runCatchError;
            }
            set
            {
                _runCatchError = value ;
            }
        }

        bool _isHasRun;
        public bool IsHasRun
        {
            get
            {
                return _isHasRun;
            }
            set
            {
               _isHasRun=value;
            }
        }

        bool _isRunRight;
        public bool IsRunRight
        {
            get
            {
                return _isRunRight;
            }
            set
            {
                _isRunRight = value ;
            }
        }

        public void OnBeforeRun()
        {
            string solutionPath = ProjectService.DefaultService.GetProjPath(ProjPath.SOLUTION);


            ProjectService.DefaultService.Project.MfData.DeleteModflowFiles(solutionPath );

            ProjectService.DefaultService.Project.MfData.WriteFiles(solutionPath);
           
        }

        public void OnEndRun()
        {
           
        }

        public void OnBeforeCommandRun(string id)
        {
            if (id=="modflow2005")
            {
               

             
               string destPath = ProjectService.DefaultService.GetProjPath(ProjPath.SOLUTION)+"mf2005.exe";

               if (!System.IO.File.Exists(destPath))
               {
                   string m2005Path = ApplicationService.DefalutService.GetApplicationPath(ApplicationPath.MODELEXEPATH) + @"mf2005.exe";

                   if (System.IO.File.Exists(m2005Path))
                   {
                       System.IO.File.Copy(m2005Path, destPath);

                   }
                   else
                   {
                       System.Windows.MessageBox.Show("未找到可运行的文件 mf2005.exe");
                   }

                   

               }



                //如果不存在就创建对应的CCF文件件

               string dirCCF = ProjectService.DefaultService.GetProjPath(ProjPath.CCF);

               if (!System.IO.Directory.Exists(dirCCF))
               {
                   System.IO.Directory.CreateDirectory(dirCCF);

               }

              

            }
            
        }

        public void OnEndCommandRun(string id)
        {
           
        }

        #endregion
    }
}
